//package action.util;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import action.pojo.FtpConnect;
//import android.content.ContentValues;
//import android.content.Context;
//import android.database.Cursor;
//import android.database.SQLException;
//import android.database.sqlite.SQLiteDatabase;
//
//public class FavoriteFTPConnectSQLite {
//	private SQLiteDatabase database;
//	private DatabaseHelper helper;
//	private String[] allColumns = {DatabaseHelper.COLUMN_ID_FAVORITE_FTP,DatabaseHelper.COLUMN_NAME_FAVORITE_FTP,
//			DatabaseHelper.COLUMN_PATH_FAVORITE_FTP,DatabaseHelper.COLUMN_FOLDER_FAVORITE_FTP,
//			DatabaseHelper.COLUMN_HOSTNAME_FAVORITE,DatabaseHelper.COLUMN_PORT_FAVORITE,DatabaseHelper.COLUMN_USERNAME_FAVORITE_FTP,
//			DatabaseHelper.COLUMN_PASSWORD_FAVORITE_FTP};
//	
//	FtpConnect ftpConnect;
//	
//	public FavoriteFTPConnectSQLite(Context context){
//		helper = new DatabaseHelper(context);
//	}
//	
//	public void open() throws SQLException {
//		database = helper.getWritableDatabase();
//	}
//
//	public void close() {
//		helper.close();
//	}
//	
//	public FtpConnect createNewFavoriteFTP(FtpConnect file) {
//		ContentValues values = new ContentValues();
//		values.put(DatabaseHelper.COLUMN_NAME_FAVORITE_FTP, file.getFtpFile().getName());
//		
//		if(file.getFtpFile().isDirectory()){
//			values.put(DatabaseHelper.COLUMN_FOLDER_FAVORITE_FTP,0);	
//		}else{
//			values.put(DatabaseHelper.COLUMN_FOLDER_FAVORITE_FTP,1);
//		}
//		
//		values.put(DatabaseHelper.COLUMN_PATH_FAVORITE_FTP, Tool.connect.getHostname()+Tool.getFTPPath(Tool.ftp_path));
//		values.put(DatabaseHelper.COLUMN_HOSTNAME_FAVORITE,file.getHostname());
//		values.put(DatabaseHelper.COLUMN_PORT_FAVORITE, file.getPort());
//		values.put(DatabaseHelper.COLUMN_USERNAME_FAVORITE_FTP, file.getUsername());
//		values.put(DatabaseHelper.COLUMN_PASSWORD_FAVORITE_FTP, file.getPassword());
//		
//		long insertId = database.insert(DatabaseHelper.TABLE_FAVORITE_FTP, null,
//				values);
//		Cursor cursor = database.query(DatabaseHelper.TABLE_FAVORITE_FTP,
//				allColumns, DatabaseHelper.COLUMN_ID_FAVORITE_FTP + " = " + insertId, null,
//				null, null, null);
//		cursor.moveToFirst();
//		FtpConnect newFtpConnect = cursorToFavorite(cursor);
//		cursor.close();
//		return newFtpConnect;
//	}
//	
//	
//	
//	public List<FtpConnect> getAllConnect() {
//		List<FtpConnect> ftpConnects = new ArrayList<FtpConnect>();
//
//		Cursor cursor = database.query(DatabaseHelper.TABLE_FAVORITE_FTP,
//				allColumns, null, null, null, null, null);
//
//		cursor.moveToFirst();
//		System.out.println(" ngan lam roi");
//		while (!cursor.isAfterLast()) {
//			ftpConnect = cursorToFavorite(cursor);
//			ftpConnects.add(ftpConnect);
//			
//			System.out.println("lst " + ftpConnect.getFtpFile().getName());
//			
//			cursor.moveToNext();
//		}
//		// Make sure to close the cursor
//		cursor.close();
//		return ftpConnects;
//	}
//	
//	public void deleteFavorite() {
//		database.delete(DatabaseHelper.TABLE_FAVORITE_FTP,null, null);
//		close();
//	}
//	
//	// update ftp
//	public boolean updateFavorite(FtpConnect connect){
//		ContentValues values = new ContentValues();
//		values.put(DatabaseHelper.COLUMN_NAME_FAVORITE_FTP, connect.getFtpFile().getName());
//		values.put(DatabaseHelper.COLUMN_PATH_FAVORITE_FTP, connect.getPath());
//		values.put(DatabaseHelper.COLUMN_FOLDER_FAVORITE_FTP, connect.getIsFolder());
//		return database.update(DatabaseHelper.TABLE_FAVORITE_FTP, values, DatabaseHelper.COLUMN_ID_FAVORITE_FTP + "=" + connect.getIdfavorite(), null) >0;
//	}
//	
//	public FtpConnect cursorToFavorite(Cursor cursor){
//		 ftpConnect = new FtpConnect();
//		try{
//			ftpConnect.setIdfavorite(cursor.getInt(0));
//			ftpConnect.setName(cursor.getString(1));
//			ftpConnect.setPath(cursor.getString(2));
//			ftpConnect.setIsFolder(cursor.getInt(3));
//			ftpConnect.setHostname(cursor.getString(4));
//			ftpConnect.setPort(cursor.getInt(5));
//			ftpConnect.setUsername(cursor.getString(6));
//			ftpConnect.setPassword(cursor.getString(7));
//		}catch(Exception e){
//			e.printStackTrace();
//		}
//		return ftpConnect;
//	}
//}
